import com.sun.xml.internal.ws.policy.privateutil.PolicyUtils;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.fs.PathFilter;
import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Job;
import org.apache.hadoop.mapreduce.lib.input.FileInputFormat;
import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat;

import java.io.FileInputStream;
import java.io.IOException;

public class WordCountDrive {
    public static void main(String[] args) throws IOException, InterruptedException, ClassNotFoundException {
        final Configuration conf = new Configuration();
        Job job = Job.getInstance(conf, "WordCountDrive");
        job.setJarByClass(WordCountDrive.class);
        job.setMapperClass(WordCountMapper.class);
        job.setReducerClass(WordCountReducer.class);
        //指定Mapper输出的kv数据类型
        job.setMapOutputKeyClass(IntWritable.class);
        job.setMapOutputValueClass(IntWritable.class);
        //指定最终输出的kv数据类型 -- Reduce
        job.setOutputKeyClass(IntWritable.class);
        job.setOutputValueClass(IntWritable.class);

        //指定job处理的原始数据路径
        FileInputFormat.setInputPaths(job,new Path("f:\\WordCountWork"));

        //指定输出结果路径
        FileOutputFormat.setOutputPath(job,new Path("f:\\OutPutWc"));
        //设置reducer数量
        job.setNumReduceTasks(1);
        //提交作业
        boolean flag = job.waitForCompletion(true);
        System.exit(flag?0:1);
    }
}
